import {user} from '../../models/3.0/user'
import { release } from '../../models/me-release'
import dateDiff  from '../../util/dateDiff'
const merelease= new release()
 const giveUser = new user()
// pages/user/user.js
Page({
  /**
   * Page initial data
   */
  data: {
    active: 0,
    userId:'',
    list:[],
    newList:[], 
    Collect:[],
    avatar:'',
    nickName:''
  },
  getUser(userId){
    let params={
      userId:userId,
      count:10,
      page:1
    }
   giveUser.getUser(params,res=>{
     this.setData({
       list:res
     })
    })
  },
  getUserRelease(userId){
    let params={
      userId:userId,
      count:10,
      page:1
    }
    merelease.getUserRelease(params,res=>{
      res.forEach((item) => {
        item.topicName = item?.topicName?.split(',')
        item.images=item.images?.split(',')
        item.date = dateDiff(+new Date(item.createDate))
        if (item.content.length > 65) {
          item.expand = true
        }
      })
        this.setData({
          newList:res
        })
    })
  },
  getCollect(userId){
    let params={
      userId:userId,
      count:10,
      page:1
    }
    merelease.getCollect(params,res=>{
      res.forEach((item) => {
        item.topicName = item?.topicName?.split(',')
        item.images=item.images?.split(',')
        item.date = dateDiff(+new Date(item.createDate))
        if (item.content.length > 65) {
          item.expand = true
        }
      })
        this.setData({
          newList:res
        })
    })
  },
  tochatroom(){
    wx.navigateTo({
      url: `../../packageA/pages/chat-room/chat-room?toUser=${this.data.nickName}&toUserId=${this.data.userId}`
  })
  },
  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
   this.setData({
    avatar:options.avatar,
    nickName:options.nickName,
    userId:options.userId
   })
   this.getUserRelease(options.userId)
   this.getCollect(options.userId)
    this.getUser(options.userId)
  },
  onShow(){
  },
  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {},

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {},

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {},

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {},

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {},

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {},

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {}
})
